<template>
  <div class="right-top">
    <div class="score-container">
      <div class="score-chart" ref="scoreChartRef"></div>
      <div class="score-right">
        <div class="score-header">
          <span class="score-title">综合评分</span>
          <span class="score-value">92.5</span>
        </div>
        <div class="score-legend">
          <div class="legend-item" v-for="(item, index) in indicators" :key="index">
            <span class="legend-dot" :style="{ backgroundColor: item.color }"></span>
            <span class="legend-label">{{ item.name }}</span>
            <span class="legend-value">{{ item.value }}分</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const scoreChartRef = ref<HTMLElement | null>(null)
let scoreChart: echarts.ECharts | null = null

// 质量指标数据
interface Indicator {
  name: string;
  value: number;
  color: string;
}

const indicators: Indicator[] = [
  { name: '外观品质', value: 95, color: '#33ffd0' },
  { name: '口感风味', value: 90, color: '#ffd700' },
  { name: '营养价值', value: 88, color: '#ff6b6b' },
  { name: '安全指标', value: 96, color: '#4dabf7' },
  { name: '新鲜度', value: 93, color: '#9775fa' }
]

// 初始化图表
const initChart = () => {
  if (!scoreChartRef.value) return
  
  scoreChart = echarts.init(scoreChartRef.value)
  
  const option = {
    radar: {
      indicator: indicators.map(item => ({
        name: item.name,
        max: 100
      })),
      radius: '70%',
      center: ['50%', '55%'],
      splitNumber: 4,
      axisName: {
        color: '#33ffd0',
        fontSize: 14,
        padding: [3, 5]
      },
      splitLine: {
        lineStyle: {
          color: [
            'rgba(51, 255, 208, 0.1)',
            'rgba(51, 255, 208, 0.2)',
            'rgba(51, 255, 208, 0.3)',
            'rgba(51, 255, 208, 0.4)'
          ]
        }
      },
      splitArea: {
        show: true,
        areaStyle: {
          color: [
            'rgba(51, 255, 208, 0.05)',
            'rgba(51, 255, 208, 0.1)',
            'rgba(51, 255, 208, 0.15)',
            'rgba(51, 255, 208, 0.2)'
          ]
        }
      },
      axisLine: {
        lineStyle: {
          color: 'rgba(51, 255, 208, 0.3)'
        }
      }
    },
    series: [{
      type: 'radar',
      data: [{
        value: indicators.map(item => item.value),
        name: '质量指标',
        areaStyle: {
          color: 'rgba(51, 255, 208, 0.2)'
        },
        lineStyle: {
          color: '#33ffd0',
          width: 2
        },
        itemStyle: {
          color: '#33ffd0'
        },
        label: {
          show: true,
          formatter: function(params: any) {
            return params.value;
          },
          color: '#33ffd0',
          fontSize: 14
        }
      }]
    }]
  }
  
  scoreChart.setOption(option)
}

// 监听窗口大小变化
const handleResize = () => {
  scoreChart?.resize()
}

onMounted(() => {
  initChart()
  window.addEventListener('resize', handleResize)
})
</script>

<style scoped>
.right-top {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
}

.score-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-shrink: 0;
  width: 200px;
}

.score-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.score-title {
  font-size: 16px;
  color: #33ffd0;
  text-shadow: 0 0 10px rgba(51, 255, 208, 0.3);
}

.score-value {
  font-size: 36px;
  font-weight: bold;
  color: #33ffd0;
  text-shadow: 0 0 15px rgba(51, 255, 208, 0.5);
}

.score-chart {
  width: 60%;
  height: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 20px;
}

.score-legend {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-label {
  flex: 1;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.legend-value {
  font-size: 14px;
  color: #33ffd0;
  font-weight: bold;
}
</style> 